<!DOCTYPE html><html lang="en"><head><title>PayoutItemCancel.aspx</title></head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"><meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0"><meta name="groc-relative-root" content=""><meta name="groc-document-path" content="PayoutItemCancel.aspx"><meta name="groc-project-path" content="PayoutItemCancel.aspx.cs"><link rel="stylesheet" type="text/css" media="all" href="assets/style.css"><script type="text/javascript" src="assets/behavior.js"></script><body><div id="meta"><div class="file-path">PayoutItemCancel.aspx.cs</div></div><div id="document"><div class="segment"><div class="comments "><div class="wrapper"><h1 id="cacnel-payout-item">Cacnel Payout Item</h1>
<p>This sample code demonstrates how you can cancel a payout item.
More Information: <a href="https://developer.paypal.com/docs/integration/direct/payouts-overview/">https://developer.paypal.com/docs/integration/direct/payouts-overview/</a></p></div></div><div class="code"><div class="wrapper"><span class="hljs-keyword">using</span> PayPal.Api;
<span class="hljs-keyword">using</span> System.Collections.Generic;

namespace PayPal.Sample
{
    <span class="hljs-keyword">public</span> <span class="hljs-keyword">partial</span> <span class="hljs-keyword">class</span> PayoutItemCancel : BaseSamplePage
    {
        <span class="hljs-keyword">protected</span> <span class="hljs-keyword">override</span> <span class="hljs-keyword">void</span> <span class="hljs-title">RunSample</span>()
        {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="api-context">Api Context</h3>
<p>Pass in a <code>APIContext</code> object to authenticate 
the call and to send a unique request id 
(that ensures idempotency). The SDK generates
a request id if you do not pass one explicitly. 
See <a href="/Source/Configuration.html">Configuration.cs</a> to know more about APIContext.</p></div></div><div class="code"><div class="wrapper">            <span class="hljs-keyword">var</span> apiContext = Configuration.GetAPIContext();</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="initialize-payout-object">Initialize <code>Payout</code> Object</h3>
<p>Initialize a new <code>Payout</code> object with details of the batch payout to be created.</p></div></div><div class="code"><div class="wrapper">            <span class="hljs-keyword">var</span> payout = <span class="hljs-keyword">new</span> Payout
            {</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h4 id="sender-batch-header">sender_batch_header</h4>
<p>Describes how the payments defined in the <code>items</code> array are to be handled.</p></div></div><div class="code"><div class="wrapper">                sender_batch_header = <span class="hljs-keyword">new</span> PayoutSenderBatchHeader
                {
                    sender_batch_id = <span class="hljs-string">"batch_"</span> + System.Guid.NewGuid().ToString().Substring(<span class="hljs-number">0</span>, <span class="hljs-number">8</span>),
                    email_subject = <span class="hljs-string">"You have a payment"</span>
                },</div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h4 id="items">items</h4>
<p>The <code>items</code> array contains the list of payout items to be included in this payout.
If <code>syncMode</code> is set to <code>true</code> when calling <code>Payout.Create()</code>, then the <code>items</code> array must only
contain <strong>one</strong> item.  If <code>syncMode</code> is set to <code>false</code> when calling <code>Payout.Create()</code>, then the <code>items</code>
array can contain more than one item.</p></div></div><div class="code"><div class="wrapper">                items = <span class="hljs-keyword">new</span> List&lt;PayoutItem&gt;
                {
                    <span class="hljs-keyword">new</span> PayoutItem
                    {
                        recipient_type = PayoutRecipientType.EMAIL,
                        amount = <span class="hljs-keyword">new</span> Currency
                        {
                            <span class="hljs-keyword">value</span> = <span class="hljs-string">"0.99"</span>,
                            currency = <span class="hljs-string">"USD"</span>
                        },
                        receiver = <span class="hljs-string">"shirt-supplier-one@mail.com"</span>,
                        note = <span class="hljs-string">"Thank you."</span>,
                        sender_item_id = <span class="hljs-string">"item_1"</span>
                    }
                }
            };</div></div></div><div class="segment"><div class="code folded"><div class="wrapper marker"><span class="c1">            // Ignore workflow code segment</span></div><div class="wrapper">            <span class="hljs-comment">// Ignore workflow code segment</span>
            <span class="hljs-preprocessor">#<span class="hljs-keyword">region</span> Track Workflow</span>
            <span class="hljs-keyword">this</span>.flow.AddNewRequest(<span class="hljs-string">"Create single, synchronous payout"</span>, payout);
            <span class="hljs-preprocessor">#<span class="hljs-keyword">endregion</span></span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="payoutcreate">Payout.Create()</h3>
<p>Creates the batch payout resource.
<code>syncMode = false</code> indicates that this call will be performed <strong>asynchronously</strong>,
and will return a <code>payout_batch_id</code> that can be used to check the status of the payouts in the batch.
<code>syncMode = true</code> indicates that this call will be performed <strong>synchronously</strong> and will return once the payout has been processed.</p>
<blockquote>
<p><strong>NOTE</strong>: The <code>items</code> array can only have <strong>one</strong> item if <code>syncMode</code> is set to <code>true</code>.</p>
</blockquote></div></div><div class="code"><div class="wrapper">            <span class="hljs-keyword">var</span> createdPayout = payout.Create(apiContext, <span class="hljs-keyword">true</span>);</div></div></div><div class="segment"><div class="code folded"><div class="wrapper marker"><span class="c1">            // Ignore workflow code segment</span></div><div class="wrapper">            <span class="hljs-comment">// Ignore workflow code segment</span>
            <span class="hljs-preprocessor">#<span class="hljs-keyword">region</span> Track Workflow</span>
            <span class="hljs-keyword">this</span>.flow.RecordResponse(createdPayout);
            <span class="hljs-preprocessor">#<span class="hljs-keyword">endregion</span></span>

            <span class="hljs-keyword">var</span> payoutItem = createdPayout.items[<span class="hljs-number">0</span>];</div></div></div><div class="segment"><div class="code folded"><div class="wrapper marker"><span class="c1">            // Ignore workflow code segment</span></div><div class="wrapper">            <span class="hljs-comment">// Ignore workflow code segment</span>
            <span class="hljs-preprocessor">#<span class="hljs-keyword">region</span> Track Workflow</span>
            <span class="hljs-keyword">this</span>.flow.AddNewRequest(<span class="hljs-string">"Cancel the payout item"</span>, description: <span class="hljs-string">"ID: "</span> + payoutItem.payout_item_id);
            <span class="hljs-preprocessor">#<span class="hljs-keyword">endregion</span></span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><h3 id="payoutcancel">Payout.Cancel()</h3>
<p>Call Payout.Cancel() to cancel the payout item.</p></div></div><div class="code"><div class="wrapper">            <span class="hljs-keyword">var</span> cancelledPayoutItem = PayoutItem.Cancel(apiContext, payoutItem.payout_item_id);</div></div></div><div class="segment"><div class="code folded"><div class="wrapper marker"><span class="c1">            // Ignore workflow code segment</span></div><div class="wrapper">            <span class="hljs-comment">// Ignore workflow code segment</span>
            <span class="hljs-preprocessor">#<span class="hljs-keyword">region</span> Track Workflow</span>
            <span class="hljs-keyword">this</span>.flow.RecordResponse(cancelledPayoutItem);
            <span class="hljs-preprocessor">#<span class="hljs-keyword">endregion</span></span></div></div></div><div class="segment"><div class="comments "><div class="wrapper"><p>For more information, please visit <a href="https://developer.paypal.com/docs/api/">PayPal Developer REST API Reference</a>.</p></div></div><div class="code"><div class="wrapper">        }
    }
}</div></div></div></div></body></html>